package com.lhf.dajiuye.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lhf.dajiuye.domain.*;
import com.lhf.dajiuye.mapper.JobDataMapper;
import com.lhf.dajiuye.mapper.SwiperDataMapper;
import com.lhf.dajiuye.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service("homeService")
public class HomeServiceImpl implements HomeService {

    @Autowired
    private SwiperDataMapper swiperDataMapper;

    @Autowired
    private JobDataMapper jobDataMapper;

    /**
     * 获取轮播图数据
     * @return
     * @throws IOException
     */
    @Override
    public List<SwiperData> getswiperDataList() throws IOException {

        List<SwiperData> swiperDataList = swiperDataMapper.getSwiperDataList();
        return swiperDataList;
    }

    /**
     * 获取分类导航栏数据
     * @return
     * @throws IOException
     */
    @Override
    public List<CatItems> getcatItemsList() throws IOException {
        List<CatItems> catItemsList = swiperDataMapper.getcatItemsDataList();
        return catItemsList;
    }

    public void saveJob(Job job){
        job.setJobId(UUID.randomUUID().toString().replace("-",""));
        job.setJobReleaseTime(new Date());
        jobDataMapper.saveJob(job);
    }

    /**
     * 获取职位信息
     * @return
     */
    @Override
    public PageInfo<Job> getJobData(String jobId,Params params) {

        Integer pageNo = params.getPageNo();
        Integer pageSize = params.getPageSize();
        // 这段代码表示，程序开始分页了，page默认值是1，pageSize默认是10，意思是从第1页开始，每页显示10条记录
        PageHelper.startPage(pageNo,pageSize);

        List<Job> jobDataList = jobDataMapper.getJobDataList(jobId,params);
        PageInfo<Job> pageInfo = new PageInfo<>(jobDataList);

        return pageInfo;
    }

    /**
     * 获取职位信息2
     * @return
     */
    @Override
    public PageInfo<Job> getJobData2(Params params) {

        Integer pageNo = params.getPageNo();
        Integer pageSize = params.getPageSize();
        // 这段代码表示，程序开始分页了，page默认值是1，pageSize默认是10，意思是从第1页开始，每页显示10条记录
        PageHelper.startPage(pageNo,pageSize);

        List<Job> jobDataList = jobDataMapper.getJobDataList2(params);
        PageInfo<Job> pageInfo = new PageInfo<>(jobDataList);

        return pageInfo;
    }

    /**
     * 根据id获取职位信息
     * @return
     */
    @Override
    public Job getJobById(String jobId) {
        Job job = jobDataMapper.getJobById(jobId);
        return job;
    }

    /**
     * 查询投递职位反馈
     * @param userId
     * @param state
     * @return
     */
    public PageInfo<Job> getJobsFeedback(int pageNum, int pageSize,String userId,int state){
        PageHelper.startPage(pageNum,pageSize);
        List<Job> jobsFeedback = jobDataMapper.getJobsFeedback(userId, state);
        PageInfo<Job> pageInfo=new PageInfo<>(jobsFeedback);
        return pageInfo;
    }

    /**
     * 职位定制
     * @return
     */
    public List<Job> jobsCustom(Job job) {
        List<Job> jobs = jobDataMapper.jobCustom(job);
        return jobs;
    }

    /**
     * 职位模糊匹配
     * @param params
     * @param params
     * @return
     */
    @Override
    public PageInfo<Job> query(Params params) {
        Integer pageNo = params.getPageNo();
        Integer pageSize = params.getPageSize();
        // 这段代码表示，程序开始分页了，page默认值是1，pageSize默认是10，意思是从第1页开始，每页显示10条记录
        PageHelper.startPage(pageNo,pageSize);

        List<Job> jobDataList = jobDataMapper.qSearch(params);
        PageInfo<Job> pageInfo = new PageInfo<>(jobDataList);

        return pageInfo;
    }

    /**
     * 获取公司信息
     * @return
     */
    @Override
    public List<Company> getComData(String comId) {
        List<Company> comDataList = jobDataMapper.getComDataList(comId);
        return comDataList;
    }
}
